/*
 * Created on Jun 9, 2005
 *
 */
package com.erclab.internal.xpresso.dataAccess;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author Enrique Rodriguez.
 *
 */
public class GenericResultSet {

	protected int numberOfColumns;
	protected String[] columnNames;
	protected ArrayList rows;
	protected int index;

	public GenericResultSet(){
		index = -1;
		rows = new ArrayList();
	}


	/**
	 * @param row
	 */
	public void addRow(String[] row) {
		rows.add(row);		
	}
	
	public boolean nextRow(){
		index++;
		if (index < rows.size())
			return true;
		else
			return false;		
	}
	
	public String[] getRow(){
		return (String[])rows.get(index);
	}
	
	public int getNumberOfRows(){
		return rows.size();
	}
	

	/**
	 * @return
	 */
	public String[] getColumnNames() {
		return columnNames;
	}

	/**
	 * @return
	 */
	public int getNumberOfColumns() {
		return numberOfColumns;
	}

	/**
	 * @param strings
	 */
	public void setColumnNames(String[] strings) {
		columnNames = strings;
	}

	/**
	 * @param i
	 */
	public void setNumberOfColumns(int i) {
		numberOfColumns = i;
	}


	/**
	 * @param columnName
	 * @return
	 */
	public String getValue(String columnName) {
		for (int i = 0; i < columnNames.length; i++){
			if(columnNames[i]!=null && columnNames[i].equalsIgnoreCase(columnName))
				return ((String[])rows.get(index))[i];
		}
		return null;
	}

}
